// vue.config.js
const ScriptSetup = require('unplugin-vue2-script-setup/webpack').default
const TransformPages = require('uni-read-pages')
const {
	webpack
} = new TransformPages()

module.exports = {
	// publicPath: '/',
	devServer: {
		proxy: {
			'/api': {
				target: 'https://api-pc-test.imiyun.com',//'http://localhost:8080/',//'https://api.test.imiyun.com/',
				ws: true, // 是否启用websockets 
				pathRewrite: {
					'^/api': ''
				},
				changeOrigin: true,
				secure: false,
				withCredentials: true,
				onProxyReq(proxyReq) {
					// 移除Origin头避免CORS问题
					proxyReq.removeHeader('Origin');
				}
			},
			'/cdn': {
				target: 'https://cdn-test.imiyun.com', //'http://localhost:8080/',//'https://api.test.imiyun.com/',
				ws: true, // 是否启用websockets 
				pathRewrite: {
					'^/cdn': ''
				},
				changeOrigin: true,
				secure: false,
				withCredentials: true
			},
			'/pay': {
				target: 'https://pay-test.imiyun.com', //'http://localhost:8080/',//'https://api.test.imiyun.com/',
				ws: true, // 是否启用websockets 
				pathRewrite: {
					'^/pay': ''
				},
				changeOrigin: true,
				secure: false,
				withCredentials: true
			},
			'/api-test': {
				target: 'https://api-test.imiyun.com',
				changeOrigin: true,
				pathRewrite: {
					'^/api-test': ''
				},
			},
			'/uba': {
				target: 'https://api-test.imiyun.com',
				changeOrigin: true,
				pathRewrite: {
					'^/uba': ''
				},
			},
		},
	},
	parallel: false,
	configureWebpack: {
		plugins: [
			ScriptSetup({
				/* options */
}),
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ['path', 'name', 'aliasPath']
					});
					return JSON.stringify(tfPages.routes)
				}, true)
			})
		],
	},
	chainWebpack(config) {
		// disable type check and let `vue-tsc` handles it
		config.plugins.delete('fork-ts-checker')
	},
}